export interface JSON{
  [key:string]:any;
}
// 包含或排除指定字段配置接口
export interface includeExcludeOptions{
  include?:Array<string>;
  exclude?:Array<string>;
}
export function decodeQuery (query:string, options:includeExcludeOptions = {}):JSON {
  const queryArr = query.split('?');
  const queryStr = queryArr[1] || queryArr[0];
  const queryList = queryStr.split(/\/?#/)[0].split('&');
  const queryData:JSON = {};
  const { include, exclude } = options;
  queryList.forEach(query => {
    const [key, value] = query.split('=');
    if (value === undefined) {
      return;
    }
    if (include !== undefined) {
      // 不匹配的字段忽略
      if (include.indexOf(key) < 0) {
        return;
      }
    } else if (exclude !== undefined) {
      // 排除匹配的字段
      if (exclude.indexOf(key) > -1) {
        return;
      }
    }
    queryData[key] = decodeURIComponent(value);
  });
  return queryData;
}